package com.rk.app.poll.client;

import java.io.Serializable;
import java.util.Date;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class Poll implements Serializable {
	private static final long serialVersionUID = 1L;

	@Persistent
	private String[] choices;

	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	private Long id;

	@Persistent
	private String pollQuestion;

	@Persistent
	private boolean state;

	@Persistent
	private Date startsOn;

	@Persistent
	private Date endsOn;

	public void close() {
		state = false;
	}

	public String[] getChoices() {
		return choices;
	}

	public Date getEndsOn() {
		return endsOn;
	}

	public Long getId() {
		return id;
	}

	public String getPollQuestion() {
		return pollQuestion;
	}

	public Date getStartsOn() {
		return startsOn;
	}

	public boolean isOpen() {
		return getEndsOn().after(new Date());
	}

	public void setChoices(String[] choices) {
		this.choices = choices;
	}

	public void setEndsOn(Date endsOn) {
		this.endsOn = endsOn;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public void setPollQuestion(String pollQuestion) {
		this.pollQuestion = pollQuestion;
	}

	public void setStartsOn(Date startsOn) {
		this.startsOn = startsOn;
	}
}
